![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@protobufjs/base64
Advanced tools
@protobufjs/base64 is a utility library for encoding and decoding base64 strings, primarily used in conjunction with Protocol Buffers in JavaScript. It provides efficient and straightforward methods to handle base64 encoding and decoding operations.
Base64 Encoding
This feature allows you to encode a Uint8Array into a base64 string. The `encode` method takes a buffer, an offset, and a length as parameters.
const base64 = require('@protobufjs/base64');
const buffer = new Uint8Array([72, 101, 108, 108, 111]);
let encoded = base64.encode(buffer, 0, buffer.length);
console.log(encoded); // Outputs: SGVsbG8=
Base64 Decoding
This feature allows you to decode a base64 string back into a Uint8Array. The `decode` method takes a base64 string, a buffer to write to, and an offset as parameters.
const base64 = require('@protobufjs/base64');
const encoded = 'SGVsbG8=';
let buffer = new Uint8Array(encoded.length);
let length = base64.decode(encoded, buffer, 0);
console.log(buffer.subarray(0, length)); // Outputs: Uint8Array(5) [ 72, 101, 108, 108, 111 ]
The `base64-js` package provides similar functionality for encoding and decoding base64 strings. It is a lightweight and efficient library that is widely used in the JavaScript ecosystem. Compared to @protobufjs/base64, `base64-js` is more general-purpose and not specifically tied to Protocol Buffers.
The `js-base64` package is another popular library for base64 encoding and decoding. It offers a simple API and is highly performant. Unlike @protobufjs/base64, `js-base64` includes additional features like URL-safe base64 encoding and decoding.
A minimal base64 implementation for number arrays.
base64.length(string: string
): number
Calculates the byte length of a base64 encoded string.
base64.encode(buffer: Uint8Array
, start: number
, end: number
): string
Encodes a buffer to a base64 encoded string.
base64.decode(string: string
, buffer: Uint8Array
, offset: number
): number
Decodes a base64 encoded string to a buffer.
License: BSD 3-Clause License
FAQs
A minimal base64 implementation for number arrays.
We found that @protobufjs/base64 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.